package com.wn34.goods.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wn34.goods.entity.GoodsType;
import com.wn34.goods.mapper.GoodsMapper;
import com.wn34.goods.mapper.GoodsTypeMapper;
import com.wn34.goods.service.GoodsService;
import com.wn34.goods.vo.GoodsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.stereotype.Controller;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
@EnableCaching
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    GoodsMapper goodsMapper;

    @Autowired
    GoodsTypeMapper goodsTypeMapper;

    @Override
    public PageInfo<GoodsVo> goodsPage(Integer now, Integer size, String goodsName, Integer typeId) {
        PageHelper.startPage(now, size);
        List<GoodsVo> list = goodsMapper.selectByPage(goodsName, typeId);
        return new PageInfo<GoodsVo>(list);
    }

    @Override
    @Cacheable(value = "emp", key = "#root.methodName")
    public List<GoodsType> goodsTypes() {
        return goodsTypeMapper.selectAll();
    }
}
